package com.xc.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class SqlSessionUtils {
    public static SqlSession getSqlSession(){
        InputStream is = null;
        SqlSession sqlSession = null;
        SqlSessionFactory build = null;
        SqlSessionFactoryBuilder sqlSessionFactoryBuilder = null;
        try {
           is  = Resources.getResourceAsStream("mybatis-config.xml");
           sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
            build = sqlSessionFactoryBuilder.build(is);
            sqlSession = build.openSession(true);

        } catch (IOException e) {
            e.printStackTrace();
        }

        return sqlSession;
    }
}
